package phone.example.com.a36kr.fragment.investfragment;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import phone.example.com.a36kr.R;
import phone.example.com.a36kr.activity.InvestDetailsActivity;
import phone.example.com.a36kr.adapter.InvestListViewAdapter;
import phone.example.com.a36kr.bean.InvestBean;
import phone.example.com.a36kr.nettool.NetTool;
import phone.example.com.a36kr.tools.BaseFragment;
import phone.example.com.a36kr.tools.MyApp;

/**
 * Created by dllo on 16/8/17.
 */
public class RaiseAllFragment extends BaseFragment{

    private ListView lv;
    private InvestListViewAdapter investViewPagerAdapter;

    private String url = "https://rong.36kr.com/api/mobi/cf/actions/list?page=1&type=all&pageSize=20";
    @Override
    protected int setLayout() {
        return R.layout.fragment_raise_all;
    }

    @Override
    protected void initView() {

        lv = bindView(R.id.raise_all_lv);
        investViewPagerAdapter = new InvestListViewAdapter(getContext());




    }

    @Override
    protected void initData() {
        final NetTool netTool = new NetTool();
        netTool.getNetData(url, InvestBean.class, new NetTool.NetListener<InvestBean>() {
            @Override
            public void onSuccess(final InvestBean investBean) {
                lv.setAdapter(investViewPagerAdapter);
                investViewPagerAdapter.setInvestBean(investBean);
                lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        Intent intent = new Intent(getContext(), InvestDetailsActivity.class);
                        intent.putExtra("ID",String.valueOf(investBean.getData().getData().get(position).getCrowdFundingId()));
                        startActivity(intent);
                    }
                });
            }

            @Override
            public void onError(String errorMsg) {
                Toast.makeText(mContext, "数据获取失败", Toast.LENGTH_SHORT).show();

            }
        });

    }
}
